﻿using System;
using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class WorkTimeOfStaffsRepository :
        BaseRepository<WorkTimeOfStaffs, SmatimeDataset.WorkTimeOfStaffsDataTable, WorkTimeOfStaffsTableAdapter>
    {
        /// <summary>
        ///     get total working of staff by companyid
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<WorkTimeOfStaffs> GetTotalWorkByCompanyId(long id, DateTime dateForm, DateTime dateTo)
        {
            using (var adapter = new WorkTimeOfStaffsTableAdapter())
            {
                using (var table = adapter.GetDataBy(id, dateForm, dateTo))
                {
                    var list = new List<WorkTimeOfStaffs>();
                    foreach (DataRow row in table.Rows)
                    {
                        var WorkTotalOfCompany = new WorkTimeOfStaffs();
                        WorkTotalOfCompany.FromDataRow(row);
                        list.Add(WorkTotalOfCompany);
                    }
                    return list;
                }
            }
        }

        /// <summary>
        ///     get total working of staff by companyid
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<WorkTimeOfStaffs> GetTotalWorkByStoreName(long id, string storeName, DateTime dateForm,
            DateTime dateTo)
        {
            using (var adapter = new WorkTimeOfStaffsTableAdapter())
            {
                using (
                    var table = adapter.GetDataByStoreName(id, storeName, dateForm,
                        dateTo))
                {
                    var list = new List<WorkTimeOfStaffs>();
                    foreach (DataRow row in table.Rows)
                    {
                        var WorkTotalOfCompany = new WorkTimeOfStaffs();
                        WorkTotalOfCompany.FromDataRow(row);
                        list.Add(WorkTotalOfCompany);
                    }
                    return list;
                }
            }
        }

        /// <summary>
        ///     get staff working in month
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<WorkTimeOfStaffs> GetStaffByClosingDay(long id, string closingTime)
        {
            using (var adapter = new WorkTimeOfStaffsTableAdapter())
            {
                using (var table = adapter.GetDataByClosingDay(id, closingTime))
                {
                    var list = new List<WorkTimeOfStaffs>();
                    foreach (DataRow row in table.Rows)
                    {
                        var WorkTotalOfCompany = new WorkTimeOfStaffs();
                        WorkTotalOfCompany.FromDataRow(row);
                        list.Add(WorkTotalOfCompany);
                    }
                    return list;
                }
            }
        }
    }
}